﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Caching;
using System.Configuration;

namespace LYMesApi.Util
{
    public static class CacheHelper
    {
        public static ObjectCache cache = MemoryCache.Default;
        public static string GetToken(string cacheKey)
        {
            var token = string.Empty;
            if (cache.Contains(cacheKey))
            {
                token = cache.GetCacheItem(cacheKey).Value as string;
            }
            return token;
        }

        public static void SetToken(string cacheKey, string token)
        {
            CacheItemPolicy policy = new CacheItemPolicy();
            policy.Priority = CacheItemPriority.NotRemovable;
            policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(Convert.ToInt32(ConfigurationManager.AppSettings["tokenCacheTime"]));//分钟
            cache.Set(cacheKey, token, policy);
        }

    }
}
